package leetcode.code1616;

public class Solution {
	public boolean checkPalindromeFormation(String a, String b) {
		return this.f(a, b) || this.f(b, a);
	}

	private boolean f(String a, String b) {
		int l = 0, r = a.length() - 1;
		while (l < r && a.charAt(l) == b.charAt(r)) {
			l++;
			r--;
		}
		if (l >= r) {
			return true;
		}
		return ff(a, l, r) || ff(b, l, r);
	}

	private boolean ff(String a, int l, int r) {
		while (l < r && a.charAt(l) == a.charAt(r)) {
			l++;
			r--;
		}
		return l >= r;
	}
}
